package com.freemyleft.left.left_app.mian.index.my.accept_setup;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.freemyleft.left.left_app.R;
import com.freemyleft.left.left_app.R2;
import com.freemyleft.left.left_app.mian.index.my.accept_setup.Teacher_default_price.TeacherDefaultPriceDelegate;
import com.freemyleft.left.left_app.mian.index.my.accept_setup.address_managerment.AddressManagementDelegate;
import com.freemyleft.left.zapp.delegates.LeftDelegate;
import com.freemyleft.left.zapp.net.RestClient;
import com.freemyleft.left.zapp.net.callback.IError;
import com.freemyleft.left.zapp.net.callback.IFailure;
import com.freemyleft.left.zapp.net.callback.ISuccess;
import com.freemyleft.left.zapp.util.LeftPreference;

import java.util.HashMap;
import java.util.Map;

import butterknife.OnClick;
//接单设置

public class AcceptOrderSetupDelegate extends LeftDelegate {
    //授课方式
    @OnClick(R2.id.tv_teaching_methods)
    void teachinMethods() {
        start(new TeachingMethodsDelegate());
    }

    //年级科目
    @OnClick(R2.id.tv_grade_subject)
    void gradeSubject() {
        start(new GradeSubjectDelegate());
    }

    //授课时间
    @OnClick(R2.id.tv_planning_time)
    void planning() {
        start(new TeachingMethodsTimeDelegate());
    }

    //地址选择
    @OnClick(R2.id.address_management)
    void addressManagerment() {
        start(new AddressManagementDelegate());
    }

    //授课距离
    @OnClick(R2.id.tv_planning_distance)
    void planningDistance() {
        start(new TeachingDistanceDelegate());
    }

    //推荐名师价格
    @OnClick(R2.id.tv_recommended_teacher)
    void recommendedTeacher() {
        start(new TeacherDefaultPriceDelegate());
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_work_accept_orde_setup;
    }

    @OnClick(R2.id.btn_tijiao)
    void BtnTijiao() {
        initData();
        String techerid = LeftPreference.getCustomAppProfile(TEACHER_ID);
        String token = LeftPreference.getCustomAppProfile(TOKEN);
        Map<String ,Object> params=new HashMap<>();
        params.put("token",token);
        params.put("teacherid",techerid);
        params.put("onr",toJson());
        params.put("grade","1,2,3,4,5,6,7,8,9,10,11,12");
        params.put("subject","1,2,3,4,5,6,7,8,9");
        params.put("teachertohome",1);
        params.put("studenttohome",1);
        params.put("otheraddr",1);
        params.put("shareaddr",1);
        params.put("times","1534741200,1536044800");
        RestClient.builder()
                .loader(getContext())
                .url("/home/teacher/set_up")
                .params(params)
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String responnse) {
                        JSONObject object = JSON.parseObject(responnse);
                        Log.e("response", responnse.toString());
                        if (object.getString("code").equals("1000")) {
                            Toast.makeText(_mActivity, "请求成功", Toast.LENGTH_SHORT).show();
                        } else if (object.getString("code").equals("1004")) {
                            Toast.makeText(_mActivity, "请登录后再尝试", Toast.LENGTH_SHORT).show();
                        }
                    }
                }).failure(new IFailure() {
            @Override
            public void onFailure() {
                Toast.makeText(_mActivity, "请求失败", Toast.LENGTH_SHORT).show();
            }
        }).error(new IError() {
            @Override
            public void onError(int code, String msg) {
                Toast.makeText(_mActivity, code + msg, Toast.LENGTH_SHORT).show();
            }
        }).buid().post();
    }

    private void initData() {

    }

    public String toJson() {
        Map<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("id", 1);
        Map value = new HashMap<>();
        value.put("id", 3);
        value.put("name", "英语");
        jsonMap.put("name", 1);
        jsonMap.put("value", value);
        Map value1 = new HashMap();
        value.put("value", value1);
        return JSON.toJSONString(jsonMap);
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {

    }
}
